from flask import Flask, render_template,request

# 建一个应用服务器
# pip install flask
app = Flask(__name__)

data = [
    {'id': 1, 'name': '中秋', 'count': 0},
    {'id': 2, 'name': '国庆', 'count': 0},
    {'id': 3, 'name': '春节', 'count': 0},
]


@app.route('/')
def index():
    return render_template('index.html', list=data)


# 点赞
@app.route('/vote')
def vote():
    id = request.args.get('id')
    for res in data:
        if res['id'] == int(id):
            res['count'] += 1
    return render_template('index.html', list=data)

# 取消点赞
@app.route('/cencel')
def cencel():
    id = request.args.get('id')
    for res in data:
        if res['id'] == int(id):
            res['count'] -= 1
    return render_template('index.html', list=data)


app.run(debug=True, port=33221, host='0.0.0.0')
